<%@language=vbscript%>
<!--#include file=..\checkSession.inc-->
<!--#include file="..\RootContent.inc"-->
<%	
	bBackfromupload=request("bBackfromupload")+1
	backform=request("backform")+1	
	bLoaiVt=Request("bLoaiVt")
	bMa=request("bMa")
	bMota=Request("bMota")
	bNam=Request("bNam")
'HienSX
	sort=Request("sort")
	if bLoaiVt="1" then		
		f=RootContent & "upload\"& cstr(bNam) &"\Den\" 
		ZipDir = f
	end if
	if bLoaiVt="2" then
		f=RootContent & "upload\"& cstr(bNam) &"\Di"
		ZipDir = f
	end if
	if bLoaiVt="3" then
		f=RootContent & "upload\"& cstr(bNam) &"\Duthao"
		ZipDir = f
	end if
	if bLoaiVt="4" then
		f=RootContent & "upload\"& cstr(bNam) &"\Noibo"
		ZipDir = f
	end if
	if bLoaiVt="5" then
		f=RootContent & "upload\"& cstr(bNam) &"\Quyetdinh"
		ZipDir = f
	end if
	if bLoaiVt="6" then
		f=RootContent & "upload\"& cstr(bNam) &"\DenCB"
		ZipDir = f
	end if
'Hien 27_06
	if bLoaiVt="7" then
		f=RootContent & "upload\"& cstr(bNam) &"\ToTrinh"
		ZipDir = f
	end if
	'Tinh so thu tu tiep theo cua vanban
	Set Post = Server.CreateObject("ActiveFile.Post")	
	'On Error Resume Next
	Post.Upload ZipDir
	Path=post.FormInputs("UploadedFile")
		if Err.number=0 then
			Dodai=Len(Path)
			i=dodai
			Do while  i>0
				if mid(Path,i,1)="\" then
					Pos=i
					exit do
				end if
				i=i-1
			Loop
			if Pos then
				Filename=right(Path,dodai-pos)
			end if
			'Tinh so thu tu tiep theo cua van ban
			sSQL="Select Sothutu from vanban_noidung where Loaivanthu ='"& bLoaiVT &"' and mavanthu ='"& bMa &"' order by sothutu"
			Set RecSTT=server.CreateObject("ADODB.Recordset")
			RecSTT.CursorType=3
			RecSTT.CacheSize=5
			RecSTT.Open sSQL,Conn
			if RecSTT.RecordCount then
				RecSTT.MoveLast
				STT=RecSTT("Sothutu")+1
			else
				STT=1
			end if
			Set ClsFile=server.CreateObject("Vinalines.ClsFile")
			bExten=ClsFile.GetExtensionFile(filename)
'Hien 21_05
			if bExTen<>"" then
				f=replace(bMa,"/","_") & "S" & cstr(STT) & "." & bExten		
			else
				f=replace(bMa,"/","_") & "S" & cstr(STT)
			end if
			Set ClsFile=nothing
			Set File=server.CreateObject("ActiveFile.File")
			'Doi ten file sau khi upload
			File.Name=ZipDir & "\" & f
			if File.Exists() then
				File.Delete()
			end if		
			File.Name=ZipDir & "\" &  Filename
			File.Rename ZipDir & "\" & f
			set File=nothing
			sSQL="Insert into Vanban_noidung(Mavanthu,Loaivanthu,Sothutu,Tentep,mota) values ('"& bMa &"','"& bLoaiVT &"',"& STT &",'"& f &"','"& replace(bMota,"'","''") &"')"
			Conn.Execute sSQL
			msg="ok"
		else
			msg="cancel"
		end if
	Conn.Close
	Set Conn=nothing
'HienSX
 	Response.Redirect "attach.asp?bMa="& server.urlencode(bMa) & "&bNam="& bNam  &"&bLoaiVT="& bLoaiVT &"&Msg=" & msg &"&sort=" & sort
%>